package cn.net.ecode.elec.api.web;

import cn.net.ecode.elec.ad.entity.ElecAd;
import cn.net.ecode.elec.ad.entity.ElecAdList;
import cn.net.ecode.elec.ad.service.ElecAdListService;
import cn.net.ecode.elec.ad.service.ElecAdService;
import cn.net.ecode.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName AppAdController
 * @Description 广告相关接口
 * @Author AlanShelby
 * @Date 2019-08-26 11:23:46 11:23
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/ad")
public class AppAdController {

    @Autowired
    private ElecAdService adService;

    @Autowired
    private ElecAdListService adListService;

    /**
     * @Method selectAdList
     * @Description 获取广告列表
     * @Author AlanShelby
     * @Date 14:14 2019/8/26 0026
     * @Param [type - 广告类型（详见系统字典 app_imgae_type）]
     * @Return cn.net.ecode.util.R
     */
    @RequestMapping("/list/{type}")
    public R list(@PathVariable String type) {
        // 根据 type 查询主表信息
        ElecAd elecAd = adService.getByType(type);
        if (elecAd == null) {
            return R.error("广告数据异常");
        }

        // 根据主表主键查询子表列表
        ElecAdList elecAdList = new ElecAdList();
        elecAdList.setAdId(elecAd.getId());
        List<ElecAdList> adList = adListService.findList(elecAdList);

        return R.ok().put("adList", adList);
    }
}
